// $ANTLR 3.1.3 Mar 17, 2009 19:23:44 CalculatorParser.g 2010-01-30 20:46:29

  package org.concepts.java.antlr.calculator;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;


import org.antlr.runtime.tree.*;

public class CalculatorParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "INT", "PLS", "MIN", "MUL", "DIV", "LPAREN", "RPAREN", "WHITESPACE"
    };
    public static final int RPAREN=10;
    public static final int WHITESPACE=11;
    public static final int PLS=5;
    public static final int INT=4;
    public static final int MIN=6;
    public static final int DIV=8;
    public static final int EOF=-1;
    public static final int MUL=7;
    public static final int LPAREN=9;

    // delegates
    // delegators


        public CalculatorParser(TokenStream input) {
            this(input, new RecognizerSharedState());
        }
        public CalculatorParser(TokenStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();

    public void setTreeAdaptor(TreeAdaptor adaptor) {
        this.adaptor = adaptor;
    }
    public TreeAdaptor getTreeAdaptor() {
        return adaptor;
    }

    public String[] getTokenNames() { return CalculatorParser.tokenNames; }
    public String getGrammarFileName() { return "CalculatorParser.g"; }


    public static class expr_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "expr"
    // CalculatorParser.g:38:1: expr : muldivexpr ( ( PLS | MIN ) muldivexpr )* ;
    public final CalculatorParser.expr_return expr() throws RecognitionException {
        CalculatorParser.expr_return retval = new CalculatorParser.expr_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token PLS2=null;
        Token MIN3=null;
        CalculatorParser.muldivexpr_return muldivexpr1 = null;

        CalculatorParser.muldivexpr_return muldivexpr4 = null;


        Object PLS2_tree=null;
        Object MIN3_tree=null;

        try {
            // CalculatorParser.g:39:2: ( muldivexpr ( ( PLS | MIN ) muldivexpr )* )
            // CalculatorParser.g:39:5: muldivexpr ( ( PLS | MIN ) muldivexpr )*
            {
            root_0 = (Object)adaptor.nil();

            pushFollow(FOLLOW_muldivexpr_in_expr47);
            muldivexpr1=muldivexpr();

            state._fsp--;

            adaptor.addChild(root_0, muldivexpr1.getTree());
            // CalculatorParser.g:39:16: ( ( PLS | MIN ) muldivexpr )*
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( ((LA2_0>=PLS && LA2_0<=MIN)) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // CalculatorParser.g:39:17: ( PLS | MIN ) muldivexpr
            	    {
            	    // CalculatorParser.g:39:17: ( PLS | MIN )
            	    int alt1=2;
            	    int LA1_0 = input.LA(1);

            	    if ( (LA1_0==PLS) ) {
            	        alt1=1;
            	    }
            	    else if ( (LA1_0==MIN) ) {
            	        alt1=2;
            	    }
            	    else {
            	        NoViableAltException nvae =
            	            new NoViableAltException("", 1, 0, input);

            	        throw nvae;
            	    }
            	    switch (alt1) {
            	        case 1 :
            	            // CalculatorParser.g:39:18: PLS
            	            {
            	            PLS2=(Token)match(input,PLS,FOLLOW_PLS_in_expr51); 
            	            PLS2_tree = (Object)adaptor.create(PLS2);
            	            root_0 = (Object)adaptor.becomeRoot(PLS2_tree, root_0);


            	            }
            	            break;
            	        case 2 :
            	            // CalculatorParser.g:39:25: MIN
            	            {
            	            MIN3=(Token)match(input,MIN,FOLLOW_MIN_in_expr56); 
            	            MIN3_tree = (Object)adaptor.create(MIN3);
            	            root_0 = (Object)adaptor.becomeRoot(MIN3_tree, root_0);


            	            }
            	            break;

            	    }

            	    pushFollow(FOLLOW_muldivexpr_in_expr60);
            	    muldivexpr4=muldivexpr();

            	    state._fsp--;

            	    adaptor.addChild(root_0, muldivexpr4.getTree());

            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "expr"

    public static class muldivexpr_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "muldivexpr"
    // CalculatorParser.g:42:1: muldivexpr : atom ( ( MUL | DIV ) atom )* ;
    public final CalculatorParser.muldivexpr_return muldivexpr() throws RecognitionException {
        CalculatorParser.muldivexpr_return retval = new CalculatorParser.muldivexpr_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token MUL6=null;
        Token DIV7=null;
        CalculatorParser.atom_return atom5 = null;

        CalculatorParser.atom_return atom8 = null;


        Object MUL6_tree=null;
        Object DIV7_tree=null;

        try {
            // CalculatorParser.g:43:2: ( atom ( ( MUL | DIV ) atom )* )
            // CalculatorParser.g:43:5: atom ( ( MUL | DIV ) atom )*
            {
            root_0 = (Object)adaptor.nil();

            pushFollow(FOLLOW_atom_in_muldivexpr74);
            atom5=atom();

            state._fsp--;

            adaptor.addChild(root_0, atom5.getTree());
            // CalculatorParser.g:43:10: ( ( MUL | DIV ) atom )*
            loop4:
            do {
                int alt4=2;
                int LA4_0 = input.LA(1);

                if ( ((LA4_0>=MUL && LA4_0<=DIV)) ) {
                    alt4=1;
                }


                switch (alt4) {
            	case 1 :
            	    // CalculatorParser.g:43:12: ( MUL | DIV ) atom
            	    {
            	    // CalculatorParser.g:43:12: ( MUL | DIV )
            	    int alt3=2;
            	    int LA3_0 = input.LA(1);

            	    if ( (LA3_0==MUL) ) {
            	        alt3=1;
            	    }
            	    else if ( (LA3_0==DIV) ) {
            	        alt3=2;
            	    }
            	    else {
            	        NoViableAltException nvae =
            	            new NoViableAltException("", 3, 0, input);

            	        throw nvae;
            	    }
            	    switch (alt3) {
            	        case 1 :
            	            // CalculatorParser.g:43:13: MUL
            	            {
            	            MUL6=(Token)match(input,MUL,FOLLOW_MUL_in_muldivexpr79); 
            	            MUL6_tree = (Object)adaptor.create(MUL6);
            	            root_0 = (Object)adaptor.becomeRoot(MUL6_tree, root_0);


            	            }
            	            break;
            	        case 2 :
            	            // CalculatorParser.g:43:20: DIV
            	            {
            	            DIV7=(Token)match(input,DIV,FOLLOW_DIV_in_muldivexpr84); 
            	            DIV7_tree = (Object)adaptor.create(DIV7);
            	            root_0 = (Object)adaptor.becomeRoot(DIV7_tree, root_0);


            	            }
            	            break;

            	    }

            	    pushFollow(FOLLOW_atom_in_muldivexpr88);
            	    atom8=atom();

            	    state._fsp--;

            	    adaptor.addChild(root_0, atom8.getTree());

            	    }
            	    break;

            	default :
            	    break loop4;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "muldivexpr"

    public static class atom_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "atom"
    // CalculatorParser.g:45:1: atom : ( INT | LPAREN expr RPAREN );
    public final CalculatorParser.atom_return atom() throws RecognitionException {
        CalculatorParser.atom_return retval = new CalculatorParser.atom_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token INT9=null;
        Token LPAREN10=null;
        Token RPAREN12=null;
        CalculatorParser.expr_return expr11 = null;


        Object INT9_tree=null;
        Object LPAREN10_tree=null;
        Object RPAREN12_tree=null;

        try {
            // CalculatorParser.g:45:8: ( INT | LPAREN expr RPAREN )
            int alt5=2;
            int LA5_0 = input.LA(1);

            if ( (LA5_0==INT) ) {
                alt5=1;
            }
            else if ( (LA5_0==LPAREN) ) {
                alt5=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 5, 0, input);

                throw nvae;
            }
            switch (alt5) {
                case 1 :
                    // CalculatorParser.g:46:5: INT
                    {
                    root_0 = (Object)adaptor.nil();

                    INT9=(Token)match(input,INT,FOLLOW_INT_in_atom106); 
                    INT9_tree = (Object)adaptor.create(INT9);
                    adaptor.addChild(root_0, INT9_tree);


                    }
                    break;
                case 2 :
                    // CalculatorParser.g:48:5: LPAREN expr RPAREN
                    {
                    root_0 = (Object)adaptor.nil();

                    LPAREN10=(Token)match(input,LPAREN,FOLLOW_LPAREN_in_atom118); 
                    pushFollow(FOLLOW_expr_in_atom121);
                    expr11=expr();

                    state._fsp--;

                    adaptor.addChild(root_0, expr11.getTree());
                    RPAREN12=(Token)match(input,RPAREN,FOLLOW_RPAREN_in_atom123); 

                    }
                    break;

            }
            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "atom"

    // Delegated rules


 

    public static final BitSet FOLLOW_muldivexpr_in_expr47 = new BitSet(new long[]{0x0000000000000062L});
    public static final BitSet FOLLOW_PLS_in_expr51 = new BitSet(new long[]{0x0000000000000210L});
    public static final BitSet FOLLOW_MIN_in_expr56 = new BitSet(new long[]{0x0000000000000210L});
    public static final BitSet FOLLOW_muldivexpr_in_expr60 = new BitSet(new long[]{0x0000000000000062L});
    public static final BitSet FOLLOW_atom_in_muldivexpr74 = new BitSet(new long[]{0x0000000000000182L});
    public static final BitSet FOLLOW_MUL_in_muldivexpr79 = new BitSet(new long[]{0x0000000000000210L});
    public static final BitSet FOLLOW_DIV_in_muldivexpr84 = new BitSet(new long[]{0x0000000000000210L});
    public static final BitSet FOLLOW_atom_in_muldivexpr88 = new BitSet(new long[]{0x0000000000000182L});
    public static final BitSet FOLLOW_INT_in_atom106 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_LPAREN_in_atom118 = new BitSet(new long[]{0x0000000000000210L});
    public static final BitSet FOLLOW_expr_in_atom121 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_RPAREN_in_atom123 = new BitSet(new long[]{0x0000000000000002L});

}